package com.testing.class7;

import com.testing.common.AutoUtils;
import com.testing.common.ExcelReader;
import com.testing.common.ExcelWriter;
import com.testing.web.WebKeywords;

import java.util.List;

/**
 * @Classname ExcelReaderTest
 * @Description 类型说明
 * @Date 2023/10/24 21:21
 * @Created by 特斯汀Roy
 */
public class ExcelReaderTest {
    public static void main(String[] args) {
        WebKeywords web = new WebKeywords();
        ExcelReader reader = new ExcelReader("Cases/WebCases.xlsx");
        //完成结果文件的复制
        ExcelWriter writer = new ExcelWriter("Cases/WebCases.xlsx", "Cases/results/WebResult-" + AutoUtils.dateStr("MMdd-HH：mm：ss") + ".xlsx");
        for (int i = 0; i < reader.getTotalSheetNo(); i++) {
            //读取和写入，同步在循环中指定相同的sheet页操作。
            reader.useSheetByIndex(i);
            writer.useSheetByIndex(i);
            for (int rowNo = 0; rowNo < reader.getRowNo(); rowNo++) {
                //每一行就是测试用例
                List<String> caseContent = reader.readLine(rowNo);
                System.out.println(caseContent);
                if (!"".equals(caseContent.get(3))&&!"关键字".equals(caseContent.get(3))) {
                    //关键字行不为空才是用例，需要执行
                    boolean result=false;
                    //假设用例默认结果是失败。
                    switch (caseContent.get(3)) {
                        case "open":
                            result=web.open(caseContent.get(4));
                            break;
                        case "visitWeb":
                            result=web.visitWeb(caseContent.get(4));
                            break;
                        case "input":
                            result=web.input(caseContent.get(4), caseContent.get(5));
                            break;
                        case "click":
                            result=web.click(caseContent.get(4));
                            break;
                        case "switchFrame":
                            result=web.switchIframe(caseContent.get(4));
                            break;
                        case "selectByText":
                            result=web.selectByText(caseContent.get(4), caseContent.get(5));
                            break;
                        case "saveTimeStampParam":
                            web.saveDateParam(caseContent.get(4), caseContent.get(5), caseContent.get(6));
                            result=true;
                            break;
                        case "halt":
                            result=web.halt(caseContent.get(4));
                            break;
                        case "closeBrowser":
                            result=web.quit();
                            break;
                    }
                    //执行完之后，写入测试结果
                    if(result){
                        writer.writeCell(rowNo,10,result?"PASS":"FAIL");
                    }else{
                        writer.writeFailCell(rowNo,10,result?"PASS":"FAIL");
                    }

                }
            }
        }
        reader.close();
        //一定记得save，才会保存结果到文件中
        writer.save();

    }

}
